package message;

import java.util.Map;

/**
 * 消息信息
 * @ClassName:       MessageInfo
 * @Description:     TODO
 * @author:          ljh
 * @version:         CMR--
 * @date:            2019年2月26日        下午2:58:09
 */
public class MessageInfo {

	private int code; //消息编号
	
	private Map<String,String> events;//事件
	
	public static final String TANK_ID = "tank_id";
	public static final String BULLET_ID = "bullet_id";
	public static final String MOVE_TYPE = "move_type";
	
	public void setCode(int code) {
		this.code = code;
	}

	public int getCode() {
		return code;
	}
	
	public Map<String, String> getEvents() {
		return events;
	}

	public void setEvents(Map<String, String> events) {
		this.events = events;
	}

	//通知创建id为tankId的坦克
	public static MessageInfo createTankEvents(String tankid) {
		MessageInfo info = new MessageInfo();
		info.code = MessageCode.CREATE_TANK;
		info.events.put(TANK_ID, tankid);
		return info;
	}
	
	public static MessageInfo destroyTankEvents(String tankid) {
		MessageInfo info = new MessageInfo();
		info.code = MessageCode.DESTROY_TANK;
		info.events.put(TANK_ID, tankid);
		return info;
	}
	
	public static MessageInfo moveTankEvents(String tankid) {
		MessageInfo info = new MessageInfo();
		info.code = MessageCode.MOVE_COMMAND;
		info.events.put(MOVE_TYPE, "tank");
		info.events.put(TANK_ID, tankid);
		return info;
	}
	
	public static MessageInfo moveBulletEvents(String bulletid) {
		MessageInfo info = new MessageInfo();
		info.code = MessageCode.MOVE_COMMAND;
		info.events.put(MOVE_TYPE, "tank");
		info.events.put(BULLET_ID, bulletid);
		return info;
	}
	
	public static MessageInfo turnTank(int turn_code, String tankid) {
		MessageInfo info = new MessageInfo();
		info.code = turn_code;
		info.events.put(TANK_ID, tankid);
		return info;
	}
	
	public static MessageInfo shootingTank(String tankid) {
		MessageInfo info = new MessageInfo();
		info.code = MessageCode.SHOOTING;
		info.events.put(TANK_ID, tankid);
		return info;
	}
	
	public static MessageInfo boom(String tankid) {
		MessageInfo info = new MessageInfo();
		info.code = MessageCode.Boom;
		info.events.put(TANK_ID, tankid);
		return info;
	}

	public interface MessageCode {
		
		//创建坦克指令
		int CREATE_TANK = 0;
		//销毁坦克指令
		int DESTROY_TANK = 1;
		
		//移动指令
		int MOVE_COMMAND = 100;
		
		//转向指令
		int TURN_LEFT = 101;
		int TURN_RIGHT = 102;
		int TURN_UP = 103;
		int TURN_DOWN = 104;
		
		//射击指令
		int SHOOTING = 110;
		
		//爆炸指令
		int Boom = 120;
	}
	
}
